package com.xiaoyu.fish.controller;

import com.xiaoyu.fish.common.Result;
import com.xiaoyu.fish.dto.LocationDto;
import com.xiaoyu.fish.pojo.Location;
import com.xiaoyu.fish.service.LocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/location")
public class LocationController {

    @Autowired
    private LocationService locationService;


    /**
     * 重命名收藏地点
     * @param locationDto
     * @return
     */
    @PutMapping()
    public Result renameLocation(@RequestBody LocationDto locationDto){
        System.out.println("重命名收藏地点");
        System.out.println(locationDto);
        String renameLocation = locationService.renameLocation(locationDto);
        return Result.success(renameLocation);
    }


    /**
     * 根据id查询对应的Location
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result selectPointOne(@PathVariable Integer id) {
        Location location = locationService.selectPointOne(id);
        List<Location> locationList = new ArrayList<>();
        locationList.add(location);
        return Result.success(locationList);
    }

    /**
     * 根据id删除收藏的地点
     *
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result deleteLocation(@PathVariable Integer id) {
        String deleteLocation = locationService.deleteLocation(id);
        return Result.success(deleteLocation);
    }

    /**
     * 保存收藏的地点
     *
     * @return
     */
    @PostMapping("/save")
    public Result savePoints(@RequestBody LocationDto locationDto) {
        System.out.println("保存收藏的地点的请求进入");
        System.out.println(locationDto);
        String savePosition = locationService.savePosition(locationDto);
        return Result.success(savePosition);
    }

    /**
     * 查询所有的收藏点
     *
     * @return
     */
    @GetMapping("/list")
    public Result listLocation() {
        List<Location> locations = locationService.listPoint();
        return Result.success(locations);
    }

}
